class Search {
    constructor() {
        this.input = document.getElementById("demo");
        this.value = this.input.value;
        this.url = "http://localhost/ic/search/data/goods.json";
        this.con = document.querySelector(".con")
        this.load()
    }
    load() {
        ajaxGet(this.url, (res) => {
            this.data = JSON.parse(res)
            this.display();

        });
    }
    display() {
        this.keys = [];
        this.valueP = [];
        for (var i = 0; i < this.data.length; i++) {
            this.valueP.push(this.data[i]);
        }
        this.addevent();
    }
    addevent() {
        var that = this;
        var str = "";
        that.con.innerHTML = str
        this.input.onblur = function() {

            for (var i = 0; i < that.valueP.length; i++) {
                if (that.valueP[i].name.indexOf(this.value) != -1) {
                    str += `
                    <div><img src="${that.valueP[i].url}" alt=""></div>
                    <div>${this.value}</div>
                    <div>单价：<span>${that.valueP[i].price}</span> </div>
                    <div>${that.valueP[i].tip}</div>
                    <div><a href="../pages/pages.html">查看详情</a></div>
                    `


                } else {
                    console.log("没有哦")
                }
            }

            that.con.innerHTML = str

        }
    }
};







new Search();